home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 5
/
Gold Medal Software - Volume 5 (Gold Medal) (1995).iso
/
windows
/
win31
/
cenviw.arj
/
PONGTIME.CMM
< prev
next >
Wrap
Text File
|
1994-03-08
|
4KB
|
107 lines
/*****************************************************************
*** PongTime - Make a bouncy clock. Randomize speed after ***
*** ver.1 each bounce, within limites. This demonstrates ***
*** control over window size and positoining, as ***
*** well as use of sound and menus. ***
*****************************************************************/
#define COL_AVERAGE_MOVE 3 // average column movement
#define ROW_AVERAGE_MOVE 3 // average row movement
#define COL_RANDOM_DELTA 1 // allowed change from average move to
#define ROW_RANDOM_DELTA 1 // randomize the bounces
#include <WinTools.lib> // lot of useful routines
#include <WinUtil.lib> // system metrics
#include <Message.lib> // Send messages to windows
#include <MenuCtrl.lib> // send menu command switching between analog and digital
window = spawn(P_NOWAIT,"CLOCK.EXE");
if ( window != NULL ) {
// Get size of the screen
ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
// will make window fill 1/4 of the screen height
WinWidth = WinHeight = ScreenHeight / 4 - 1;
// Get Initial position of the window
GetWindowRect(window,WinPos);
// find menu items for analog and digital
AnalogMenuID = FindMenuString(GetMenu(window),"Analog");
DigitalMenuID = FindMenuString(GetMenu(window),"Digital");
ViewingAnalog = MF_CHECKED & GetMenuState(GetMenu(window),AnalogMenuID,MF_BYCOMMAND);
// start random direction and delta
srand();
ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,rand() & 1);
RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,rand() & 1);
// Finally, keep bouncing the window around at every interval
while ( IsWindow(window) ) {
// move window to new Row and Col position
WinPos.right = (WinPos.left += ColSpeed) + WinWidth;
WinPos.bottom = (WinPos.top += RowSpeed) + WinHeight;
SetWindowRect(window,WinPos);
// check if needs to bounce back to to hitting desktop edge
if ( ColSpeed < 0 ) {
if ( WinPos.left < 0 )
Bounce(),
ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,TRUE);
} else {
if ( ScreenWidth <= WinPos.right )
Bounce(),
ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,FALSE);
}
if ( RowSpeed < 0 ) {
if ( WinPos.top < 0 )
Bounce(),
RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,TRUE);
} else {
if ( ScreenHeight <= WinPos.bottom )
Bounce(),
RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,FALSE);
}
}
}
Bounce() // make a beep sound, and change state of the clock
{
WinBeep();
MenuCommand(window,ViewingAnalog ? DigitalMenuID : AnalogMenuID,True);
ViewingAnalog = !ViewingAnalog;
}
//****** ROUTINES CALLED BY THE ABOVE CODE *******
GetRandomSpeed(average,deviation,positive) // if not positive then negative
{
// get a random deviation from average
deviate = (rand() % (2*deviation + 1)) - deviation;
if ( positive )
return( average + deviate );
else
return( -average - deviate );
}
IsWindow(WindowHandle)
{
return DynamicLink("USER","ISWINDOW",SWORD16,PASCAL,WindowHandle);
}
WinBeep()
{
#define MESSAGE_BEEP_ORDINAL 104
DynamicLink("USER.EXE",MESSAGE_BEEP_ORDINAL,SWORD16,PASCAL,0);
}